package com.thb.pay.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.thb.pay.db.service.impl.BaseServiceImpl;
import com.thb.pay.system.entity.SysUserResource;
import com.thb.pay.system.mapper.SysUserResourceMapper;
import com.thb.pay.system.service.SysUserResourceService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * <p>
 * 系统-用户资源表 服务实现类
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Service
public class SysUserResourceServiceImpl extends BaseServiceImpl<SysUserResourceMapper, SysUserResource> implements SysUserResourceService {

    @Override
    public void addResourceListByUserId(Long userId, List<Long> resourceIds) {
        Assert.notNull(userId, "userId.not.null");
        Assert.notEmpty(resourceIds, "resourceIds.not.null");
        LambdaQueryWrapper<SysUserResource> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUserResource::getUserId, userId);
        super.delete(wrapper);
        List<SysUserResource> permissionList = Lists.newArrayList();
        resourceIds.forEach(resourceId -> {
            SysUserResource sysUserResource = new SysUserResource();
            sysUserResource.setResourceId(resourceId);
            sysUserResource.setUserId(userId);
            permissionList.add(sysUserResource);
        });
        super.insertBatch(permissionList, 15);
    }
}
